package com.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.entity.User;
import com.health.entity.pojo.dto.UserDTO;
import com.health.entity.pojo.vo.QueryAdminVO;
import com.health.mapper.UserMapper;
import com.health.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author sanchuan
 * @since 2023-04-22
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    private LambdaQueryWrapper<User> wrapper;

    /**
     * 获得用户列表分页数据+条件查询
     * @param pageNum
     * @param pageSize
     * @param userDTO
     * @return
     */
    @Override
    public IPage<User> listUserPage(Integer pageNum, Integer pageSize, UserDTO userDTO) {
        // 分页
        List<User> userOS = userMapper.listUserPage(userDTO);
        List<User> list = new ArrayList<>();
        int curIdx = pageNum > 1 ? (pageNum - 1) * pageSize : 0;
        for (int i = 0; i < pageSize && curIdx + i < userOS.size(); i++) {
            list.add(userOS.get(curIdx + i));
        }
        IPage<User> iPage = new Page<>(pageNum,pageSize);
        iPage.setRecords(list);
        iPage.setTotal(userOS.size());
        return iPage;
    }

    /**
     * 封禁用户
     * @param isLock
     * @param ids
     * @return
     */
    @Override
    public Boolean banUserForever(Integer isLock,List<Integer> ids) {
        return userMapper.banUserForever(isLock,ids);
    }

    /**
     * 解封用户
     * @param userId
     * @return
     */
    @Override
    public Boolean unblockingUser(Integer userId) {
        return userMapper.unblockingUser(userId);
    }

}
